#include "IPParser.h"
#include "StringUtils.h"
#include <string.h>

void IPStringToOctets (const char *ipString, IPOctets* ipOctets) {
	const char *ipStringNextDot;
	char parseBuffer[3 + 1];
	int octets[4];
	int octetCount;
	size_t octetSize;
	
	for (octetCount = 0; octetCount <= 3; octetCount++) {
		ipStringNextDot = strchr (ipString, '.');
		if (ipStringNextDot != NULL)
			octetSize = ipStringNextDot - ipString;
		else
			octetSize = strlen(ipString);

		memcpy(parseBuffer, ipString, octetSize);
		parseBuffer[octetSize] = 0;

		octets[octetCount] = stringToInt(parseBuffer);
		
		ipString = ipStringNextDot + 1;
	}
	ipOctets->first = octets[0];
	ipOctets->second = octets[1];
	ipOctets->third = octets[2];
	ipOctets->fourth = octets[3];
}
